
package Project.GUI;

import Project.bussiness.Check;
import Project.bussiness.Doctor;
import Project.bussiness.Patient;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


public class EditPatients extends javax.swing.JInternalFrame {

    int id = 0;
    int vt = 0;
    int flag = 0;
    Date birthday=null;

    /** Creates new form EditPatients */
    public EditPatients() {
        try {

            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
        initComponents();
       
//        for (int i = 1; i <= 31; i++) {
//            cmbDate.addItem(i);
//        }
//        for (int i = 1; i < 12; i++) {
//            cmbMonth.addItem(i);
//        }
//        for (int i = 2009; i > 1900; i--) {
//            cmbYear.addItem(i);
//        }
//        Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
//        setBounds((screeSize.width-1000)/2,(screeSize.height-600)/2,1000,600);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        panelFilter = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        comFilter = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        txtFilter = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        ListPatient = new javax.swing.JList();
        butOK = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtLastName = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtHeight = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAddress = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        comSex = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        comBooldType = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtWeight = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtNotes = new javax.swing.JTextArea();
        comBenif = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtdate = new javax.swing.JTextField();
        txtMonth = new javax.swing.JTextField();
        txtYear = new javax.swing.JTextField();
        btnsetdate = new javax.swing.JButton();
        txtdatetimes = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        butSave = new javax.swing.JButton();
        butEdit = new javax.swing.JButton();
        butDelete = new javax.swing.JButton();
        butClose = new javax.swing.JButton();
        btnInsert = new javax.swing.JButton();

        setClosable(true);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        panelFilter.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel1.setText("Filtered By");

        comFilter.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "Name" }));

        jLabel2.setText("Look For");

        ListPatient.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        ListPatient.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                ListPatientValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(ListPatient);

        butOK.setText("OK");
        butOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butOKActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter);
        panelFilter.setLayout(panelFilterLayout);
        panelFilterLayout.setHorizontalGroup(
            panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup()
                .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLabel1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(comFilter, 0, 136, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabel2))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtFilter, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFilterLayout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(butOK)))
                .addContainerGap())
        );
        panelFilterLayout.setVerticalGroup(
            panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFilterLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(butOK)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel3.setFont(new java.awt.Font("Times New Roman", 2, 24));
        jLabel3.setText("Information Of Patient");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(195, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(159, 159, 159))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel3)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Informations", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel4.setText("First Name");

        txtFirstName.setEditable(false);

        jLabel5.setText("Last Name");

        txtLastName.setEditable(false);

        jLabel7.setText("Height");

        txtHeight.setEditable(false);

        jLabel8.setText("Cm");

        jLabel9.setText("Address");

        txtAddress.setColumns(20);
        txtAddress.setEditable(false);
        txtAddress.setRows(5);
        jScrollPane2.setViewportView(txtAddress);

        jLabel10.setText("Sex");

        comSex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));

        jLabel11.setText("BloodType");

        comBooldType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A", "B", "AB", "O" }));

        jLabel12.setText("Email");

        txtEmail.setEditable(false);

        jLabel13.setText("BirthDate");

        jLabel14.setText("Phone");

        txtPhone.setEditable(false);

        jLabel15.setText("Weight");

        txtWeight.setEditable(false);

        jLabel16.setText("Kg");

        jLabel17.setText("Notes");

        txtNotes.setColumns(20);
        txtNotes.setEditable(false);
        txtNotes.setRows(5);
        jScrollPane3.setViewportView(txtNotes);

        comBenif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Insurance", "Nomarl" }));

        jLabel6.setText("Benificiary");

        jLabel18.setText("Insurance Deadline");

        btnsetdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/dateti.jpeg"))); // NOI18N
        btnsetdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsetdateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel9)
                            .addComponent(jLabel5)
                            .addComponent(jLabel14)
                            .addComponent(jLabel7)
                            .addComponent(jLabel15))
                        .addGap(34, 34, 34)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                                    .addComponent(txtLastName, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                                    .addComponent(txtFirstName, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(txtHeight, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(txtWeight, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel16)))
                                .addGap(32, 32, 32))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtdate, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtYear, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel12)
                            .addComponent(jLabel11)
                            .addComponent(jLabel13)
                            .addComponent(jLabel17))
                        .addGap(17, 17, 17)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
                            .addComponent(comBooldType, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
                            .addComponent(comSex, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(comBenif, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtdatetimes, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                                .addComponent(btnsetdate, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel6))
                .addGap(44, 44, 44))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(comSex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comBooldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel14)
                        .addComponent(jLabel12))
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel13)
                    .addComponent(btnsetdate)
                    .addComponent(txtdatetimes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(comBenif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(txtWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(43, 43, 43))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(txtdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33)
                        .addComponent(jLabel17))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Options", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        butSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.gif"))); // NOI18N
        butSave.setText("Update");
        butSave.setEnabled(false);
        butSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butSaveActionPerformed(evt);
            }
        });

        butEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit.png"))); // NOI18N
        butEdit.setText("Edit");
        butEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butEditActionPerformed(evt);
            }
        });

        butDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/delete.png"))); // NOI18N
        butDelete.setText("Delete");
        butDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butDeleteActionPerformed(evt);
            }
        });

        butClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/exit.GIF"))); // NOI18N
        butClose.setText("Close");
        butClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butCloseActionPerformed(evt);
            }
        });

        btnInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.gif"))); // NOI18N
        btnInsert.setText("Insert");
        btnInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(butSave)
                .addGap(17, 17, 17)
                .addComponent(butEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(btnInsert, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(butDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(butClose, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(butEdit)
                    .addComponent(butClose)
                    .addComponent(butDelete)
                    .addComponent(btnInsert)
                    .addComponent(butSave))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(panelFilter, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new java.awt.GridBagConstraints());

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed
        reset();
        butSave.setEnabled(true);
        txtFirstName.setEditable(true);
        txtLastName.setEditable(true);
        txtAddress.setEditable(true);
        //txtBirthday.setEditable(true);
        txtEmail.setEditable(true);
        txtHeight.setEditable(true);
        txtWeight.setEditable(true);
        txtNotes.setEditable(true);
        txtPhone.setEditable(true);
        flag = 0;
    }//GEN-LAST:event_btnInsertActionPerformed
    private boolean CheckValue() {
        if ((!Check.checkName(txtFirstName.getText())) || (txtFirstName.getText().length() == 0)) {
            JOptionPane.showMessageDialog(this, "The First Name field Error or blank");
            return false;
        }
        if (!Check.checkName(txtLastName.getText()) || txtLastName.getText().length() == 0) {
            JOptionPane.showMessageDialog(this, "The Last Name field Error or blank");
            return false;
        }
        if (txtAddress.getText().length() == 0) {
            JOptionPane.showMessageDialog(this, "The Address field cannot be blank");
            return false;
        }
        if (!Check.checkPhone(txtHeight.getText()) || txtHeight.getText().length() == 0) {
            JOptionPane.showMessageDialog(this, "The Height field Error or blank");
            return false;
        }
        if (!Check.checkPhone(txtWeight.getText()) || txtWeight.getText().length() == 0) {
            JOptionPane.showMessageDialog(this, "The Weight field Error or blank");
            return false;
        }
        if (!Check.checkPhone(txtPhone.getText()) || txtPhone.getText().length() == 0) {
            JOptionPane.showMessageDialog(this, "The Phone field Error or blank");
            return false;
        }
        return true;
    }

    private void reset() {
        txtAddress.setText("");
//        cmbDate.setSelectedItem("1");
//        cmbMonth.setSelectedItem("1");
//        cmbYear.setSelectedItem("1990");
        txtdate.setText("");
        txtMonth.setText("");
        txtYear.setText("");
        txtEmail.setText("");
        txtFirstName.setText("");
        txtHeight.setText("");
        txtLastName.setText("");
        txtNotes.setText("");
        txtPhone.setText("");
        txtWeight.setText("");
        comBooldType.setSelectedIndex(0);
        comSex.setSelectedIndex(0);

    }
    private void butCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butCloseActionPerformed
// TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_butCloseActionPerformed

    private void butDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butDeleteActionPerformed
        try {
            if (id == -1) {
                JOptionPane.showMessageDialog(this, "You have not choice patient to delete");
            }
            Patient.deletePatient(id);
            model.remove(vt);

        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Can not delete patient information");
        }
        ListPatient.setModel(model);
    }//GEN-LAST:event_butDeleteActionPerformed

    private void butSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSaveActionPerformed
        if (!CheckValue()) {
            return;
        }
       
       // String birth = new String();
       // birth = cmbMonth.getSelectedItem() + "/" + cmbDate.getSelectedItem() + "/" + cmbYear.getSelectedItem();
        Patient p = new Patient();
        p.setFirstName(txtFirstName.getText());
        p.setLastName(txtLastName.getText());
        p.setBirthDay(txtdatetimes.getText());
        p.setAddress(txtAddress.getText());
        p.setBloodType(comBooldType.getSelectedItem().toString());
        p.setEmail(txtEmail.getText());
        p.setHeight(Float.parseFloat(txtHeight.getText()));
        p.setNotes(txtNotes.getText());
        p.setPhone(txtPhone.getText());
        p.setSex(comSex.getSelectedIndex());
        p.setWeight(Float.parseFloat(txtWeight.getText()));
        p.setBenificiary(comBenif.getSelectedIndex());
        if (txtMonth.getText().isEmpty()) {
            p.setInsuranceDeadline("");
        } else {
            p.setInsuranceDeadline(txtMonth.getText() + "/" + txtdate.getText() + "/" + txtYear.getText());
        }
        if (flag == 0) {
            try {
                Patient.insertPatient(p);
                JOptionPane.showMessageDialog(this, "Insert successful");
                reset();
            } catch (SQLException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "cannot insert patient");
            }
        } else {
            try {
                Patient.updatePatient(id, p);
                JOptionPane.showMessageDialog(this, "Update successful");
                reset();
            } catch (SQLException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, "Can not update patient information");
            }
        }


    }//GEN-LAST:event_butSaveActionPerformed

    private void butEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butEditActionPerformed

        butSave.setEnabled(true);
        txtFirstName.setEditable(true);
        txtLastName.setEditable(true);
        txtAddress.setEditable(true);
        //txtBirthday.setEditable(true);
        txtEmail.setEditable(true);
        txtHeight.setEditable(true);
        txtWeight.setEditable(true);
        txtNotes.setEditable(true);
        txtPhone.setEditable(true);
        flag = 1;
    }//GEN-LAST:event_butEditActionPerformed

    private void ListPatientValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ListPatientValueChanged
// TODO add your handling code here:
        vt = ListPatient.getSelectedIndex();
        if (vt == -1) {
            return;
        }
        Patient pa = new Patient();
        pa = (Patient) v.get(vt);
        id = pa.getPatientID();
        if (pa.getSex() == 0) {
            comSex.setSelectedIndex(0);
        } else {
            comSex.setSelectedIndex(1);
        }
        String s = new String();
        s = pa.getBloodType();
        String b = s.substring(0, 2);
        if (b.equalsIgnoreCase("A ")) {
            comBooldType.setSelectedItem("A");
        }
        if (b.equalsIgnoreCase("B ")) {
            comBooldType.setSelectedItem("B");
        }
        if (b.equalsIgnoreCase("AB")) {
            comBooldType.setSelectedItem("AB");
        }
        if (b.equalsIgnoreCase("O ")) {
            comBooldType.setSelectedItem("O");
        }
        txtAddress.setText(pa.getAddress());
         txtdatetimes.setText(pa.getBirthDay());
       // String bithday = pa.getBirthDay();
//        int year = Integer.parseInt(bithday.substring(0, 4));
//        int date = Integer.parseInt(bithday.substring(5, 7));
//        int month = Integer.parseInt(bithday.substring(8, 10));
//        cmbDate.setSelectedItem(date);
//        cmbMonth.setSelectedItem(month);
//        cmbYear.setSelectedItem(year);
        txtEmail.setText(pa.getEmail());
        txtFirstName.setText(pa.getFirstName());
        txtHeight.setText(((Float) pa.getHeight()).toString());
        txtWeight.setText(((Float) pa.getWeight()).toString());
        txtLastName.setText(pa.getLastName());
        txtNotes.setText(pa.getNotes());
        txtPhone.setText(pa.getPhone());
        String day = pa.getInsuranceDeadline();
        if (!day.equalsIgnoreCase("1900-01-01 00:00:00.0")) {
            String y = (day.substring(0, 4));
            String d = (day.substring(5, 7));
            String m = (day.substring(8, 10));
            txtdate.setText(d);
            txtMonth.setText(m);
            txtYear.setText(y);
        } else {
            txtdate.setText("");
            txtMonth.setText("");
            txtYear.setText("");
        }

    }//GEN-LAST:event_ListPatientValueChanged

    private void butOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butOKActionPerformed
// TODO add your handling code here:
        model.removeAllElements();
        v = null;
        String select = comFilter.getSelectedItem().toString();
        try {
            if (txtFilter.getText().length() == 0) {
                v = Patient.getAllPatient();
                System.out.println("NON");
            }
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }
        if (txtFilter.getText().length() != 0) {
            try {
                if (select == "ID") {
                    try {
                        v = Patient.getPatientByID(Integer.parseInt(txtFilter.getText()));
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "ID error");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                if (select == "Name") {
                    v = Patient.getPatientByName(txtFilter.getText());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if (v != null) {
            for (int i = 0; i < v.size(); i++) {
                if (select == "Name") {
                    Patient dt = (Patient) v.get(i);
                    model.addElement(dt.getFirstName() + " " + dt.getLastName());
                } else {
                    Patient dt = (Patient) v.get(i);
                    model.addElement(dt.getPatientID());
                }
            }
        }
        ListPatient.setModel(model);
    }//GEN-LAST:event_butOKActionPerformed

    private void btnsetdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsetdateActionPerformed
        // TODO add your handling code here:

        DateChooser dateChooser = new DateChooser((Frame) null, "Select your birthday");
        Date getDate = new Date();
        getDate = dateChooser.select(getDate);
        if(getDate== null) {
            birthday = new Date();
            return;
        }
        birthday = getDate;
        SimpleDateFormat formatDate = new SimpleDateFormat("MM/dd/yyyy");
        txtdatetimes.setText(formatDate.format(birthday));
    }//GEN-LAST:event_btnsetdateActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList ListPatient;
    private javax.swing.JButton btnInsert;
    private javax.swing.JButton btnsetdate;
    private javax.swing.JButton butClose;
    private javax.swing.JButton butDelete;
    private javax.swing.JButton butEdit;
    private javax.swing.JButton butOK;
    private javax.swing.JButton butSave;
    private javax.swing.JComboBox comBenif;
    private javax.swing.JComboBox comBooldType;
    private javax.swing.JComboBox comFilter;
    private javax.swing.JComboBox comSex;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel panelFilter;
    private javax.swing.JTextArea txtAddress;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFilter;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtHeight;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JTextField txtMonth;
    private javax.swing.JTextArea txtNotes;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtWeight;
    private javax.swing.JTextField txtYear;
    private javax.swing.JTextField txtdate;
    private javax.swing.JTextField txtdatetimes;
    // End of variables declaration//GEN-END:variables
    Vector v = new Vector();
    DefaultListModel model = new DefaultListModel();
}
